package com.sun.service;

import com.sun.model.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**|
 * 服务的降级（对类进行操作）
 * 如果调用DeptClientServer方法中失败就叫他走这个实现类，并把DeptClientServer关闭，让出资源
 */

@Component
public class DeptClientServerFallBackFactory implements FallbackFactory {

    @Override
    public DeptClientServer create(Throwable cause) {
        return new DeptClientServer() {
            @Override
            public Dept queryDeptById(int id) {
                return new Dept().setDeptNo(id).setDeptName("部门不存在，客户端提供降级服务，这个服务将被关闭");
            }

            @Override
            public List<Dept> queryAll() {
                return Arrays.asList(new Dept());
            }

            @Override
            public boolean addDept(Dept dept) {
                return false;
            }
        };
    }
}
